<script src='<?php echo DIR_JS?>ui.datepicker.js' type='text/javascript' language='javascript'> </script>
<div class="section" id="sitemaplist">
  <div class="section-title">Thông tin đặt báo</div>
  <div class="section-content padding1">
    <form name="frm" id="frm" action="<?php echo $action?>" method="post" enctype="multipart/form-data">
    <input type="hidden" id="diachi" name="diachi" value="" class="text" />
      <div class="button right">

        
        <a class="button exit" href="?route=deliman/khachhang">Trở về</a>
        <input type="hidden" name="khachhangid" id="khachhangid" value="<?php echo $item['khachhangid']?>">
        <input type="hidden" name="masokhachhang" value="<?php echo $item['masokhachhang'] ?>" />
       	<input type="hidden" name="nhanviengiaoid" id="nhanviengiaoid" value="<?php echo $nhanviengiao ?>" />
      </div>
      <div class="clearer">^&nbsp;</div>
      <div id="error" class="error" style="display:none"></div>
      <div>
      	<p>
          	<label>Khách hàng:</label>
         	<?php echo $item['hoten']?>
        </p>
        <p>
          <label>Địa chỉ:</label>
          <?php echo $item['diachi']?>
        </p>
        <p>
          <label>Email:</label>
		<?php echo $item['email']?>
        </p>
        <p>
          <label>Điện thoại:</label>
			<?php echo $item['dienthoai']?>
        </p>
        <br />
      	<div id="ben-search">
        <div class="left" style="padding-bottom:10px">
        	<label>Loại báo:</label>
                <select id="loaibaoid" name="loaibaoid">
                    <option value="">----Chọn tất cả----</option>
                        <?php echo $loaibao ?>
                </select>
        	<script language="javascript">
						$(function() {
							$("#tungay").datepicker({
									changeMonth: true,
									changeYear: true,
									dateFormat: 'dd-mm-yy'
									});
							$("#denngay").datepicker({
									changeMonth: true,
									changeYear: true,
									dateFormat: 'dd-mm-yy'
									});
							});
			</script>
        	<label>Ngày phát hành: từ</label>
            <input type="text" id="tungay" name="tungay" class="text" />
            <label>đến</label>
            <input type="text" id="denngay" name="denngay" class="text" />
               	<script language="javascript">
						$(function() {
							$("#dattungay").datepicker({
									changeMonth: true,
									changeYear: true,
									dateFormat: 'dd-mm-yy'
									});
							$("#datdenngay").datepicker({
									changeMonth: true,
									changeYear: true,
									dateFormat: 'dd-mm-yy'
									});
							});
				</script>
            <label>Ngày đặt báo: từ</label>
            <input type="text" id="dattungay" name="dattungay" class="text" />
            <label>đến</label>
            <input type="text" id="datdenngay" name="datdenngay" class="text" />
			</div>
 
            <a class="button-other search" onClick="searchForm()">Tìm kiếm</a>
            <a class="button all" id="btnAll">Xem tất cả</a>
            <div class="clearer">^&nbsp;</div>
        </div>
       
        <table class="data-table" width="100%">
        	<thead>
            	 <tr>
                    <th>STT</th>                   
                    <th>Tên loại báo</th>
                    <th>Tên kỳ báo</th>
                    <th>Ngày phát hành</th>
                    <th>Ngày đặt báo</th>
                    <th>Số lượng đặt</th>
                    <th>Giá bán</th>
                   	<th>Tình trạng</th>
                    <th>Công cụ</th>                            
                </tr>
            </thead>    
            <?php
            if(count($datas) == 0)
            {
            ?>
              	<tr>
            	<td colspan="9">
                <div class="text-center">
            		<span class="thongbaokhongcodulieu">Không có dữ liệu trong hệ thống</span>
                </div>
                </td>
            </tr>
            <?php
            }
            else
            {
            	$index = 1;
            	foreach($datas as $item)
                {
            ?>
            <tbody>
            
            	<tr>
                	<td><?php echo $index++?></td>
                    <td><?php echo $item['tenloaibao'] ?></td>
                    <td><?php echo $item['tenkybao']?></td>
                    <td><?php echo $this->date->formatMySQLDate($item['ngayphathanh']) ?></td>
                    <td><?php echo $this->date->formatMySQLDate($item['ngaydat']) ?></td>
                    <?php
                    	$cls = "";
                        $style="";
                    	if($item['trangthai']=='dagiao')
                        {
                        	$cls = "disabled";
                            $style = "style='background:#CCC; color:white;'";
                       	}
                    ?>
                    <td width="10%"><input type="text" class="text number" name="soluongdat" id="soluongdat<?php echo $item['id']?>" value="<?php echo $item['soluongdat']?>" <?php echo $style; echo $cls ?> /></td>
                    <td><?php echo $this->string->numberFormate($item['giaban']) ?></td>
                    <td><?php echo $trangthai[$item['trangthai']] ?></td>
                    <td>
                    <?php 
                    $cls = "";
                    $confirm = "btnConfirm";
                    if($item['trangthai']=='dagiao')
                    {
                    	$cls ="disabled";
                        $confirm = "";
                    }
                    ?>
                    <input type="button" class="button confirm <?php echo $cls?> <?php echo $confirm?>" ref="<?php echo $item['id'] ?>"  value="Cập nhật" name="btnConfirm" id="btnConfirm<?php echo $item['id']?>" />
                    </td>
                </tr>
            </tbody>
            <?php
            	}
            }
            ?>
        </table>
      </div>
    </form>
  </div>
</div>

<script language="javascript">
$(document).ready(function(){
		
		$("#khuvucid").change(function(){
			$('#khachhangid').load('?route=deliman/giaobao/getkhachhang&khuvucid='+$('#khuvucid').val(), function(){
				$("#khachhangid").val("<?php echo $_GET['khachhangid']?>");
			});
			
		});
		$("#khuvucid").change();
		
		$('#btnAll').click(function(){
			btnAll();
		});
		
		$('.btnConfirm').click(function(){
			//alert($(this).attr('ref'));
			//alert($('#nhanviengiaoid').val());
			//Gui request len sever
						
			
			$.post("?route=deliman/khachhang/updatethongtindatbao", 
			{
				id:$(this).attr('ref'),
				
				soluongdat:$('#soluongdat' + $(this).attr('ref')).val(),
				//Cap nhat lai khi co phan login nhan vien
				//nhanviengiaoid:$('#nhanviengiaoid').val()
			},
			
			function(data){
				//Hien thi ngay server tra ve
				//alert(data);
				obj = jQuery.parseJSON(data);
				if(obj.error == '')
				{
					/*id=obj.id;
					ngaygiao = obj.ngaygiao;
					soluongdagiao = obj.soluongdagiao;
					$('#ngaygiao'+id).html(ngaygiao);
					$('#soluongdagiao'+id).val(soluongdagiao);
					//Chuyen text box nhap lieu -> readonly va an nut confirm	
					$('#ghichu'+id).attr('readonly','readonly');
					$('#btnConfirm'+id).attr('disabled','disabled');
					$(this).hide();
					window.location.reload();*/
					alert("Bạn đã cập nhật thành công");
				}
				else
				{
					alert(obj.error);	
				}
			});	
		});
				
});

/*function save()
{
	$.blockUI({ message: "<h1>Please wait...</h1>" }); 
		
	$.post("?route=deliman/khachhang/savethongtindatbao", $("#frm").serialize(),
		function(data){
			if(data == "true")
			{
				window.location = "?route=deliman/khachhang";
				
			}
			else
			{
			
				$('#error').html(data).show('slow');
				$.unblockUI();
				
			}
			
		}
	);
}*/



function searchForm()
{
	var url ="?route=deliman/khachhang/xemthongtindatbao&khachhangid=" + $("#khachhangid").val();
		
	if($("#tungay").val() != "")
		url += "&tungay="+ $("#tungay").val();
	if($("#denngay").val() != "")
		url += "&denngay=" + $("#denngay").val();
	if($("#dattungay").val() != "")
		url += "&dattungay="+ $("#dattungay").val();
	if($("#datdenngay").val() != "")
		url += "&datdenngay=" + $("#datdenngay").val();
	if($("#loaibaoid").val() != "")
		url += "&loaibaoid=" + $("#loaibaoid").val();
	window.location = url;
	
}

function btnAll()
{
	var url ="?route=deliman/khachhang/xemthongtindatbao&khachhangid=" + $("#khachhangid").val();
	window.location = url;	
}

$("#tungay").val("<?php echo $_GET['tungay']?>");
$("#denngay").val("<?php echo $_GET['denngay']?>");
$("#khachhangid").val("<?php echo $_GET['khachhangid']?>");
$("#loaibaoid").val("<?php echo $_GET['loaibaoid']?>");
$("#dattungay").val("<?php echo $_GET['dattungay']?>");
$("#datdenngay").val("<?php echo $_GET['datdenngay']?>");
</script>